﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Manager;
using Model;

namespace Controllers
{
    [HandleError]
    public class HomeController : Controller
    {
        public ICompanyManager CompanyManager { get; set; }

        public IUserManager UserManager { get; set; }

        public ActionResult Index()
        {
            ViewData["Message"] = "Welcome to ASP.NET MVC!";

            ViewData["Company"] = CompanyManager.LoadAll();

            return View();
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult SaveUser(User user)
        {
            user.CurrentCompany = CompanyManager.Get(user.CurrentCompany.CompanyID);
            UserManager.Save(user);

            return RedirectToAction("GetCompany", "Home", new { id = user.CurrentCompany.CompanyID });
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult SaveCompany(Company company)
        {
            CompanyManager.Save(company);

            return RedirectToAction("Index", "Home");
        }

        public ActionResult GetCompany(int id)
        {
            ViewData["Company"] = CompanyManager.Get(id);

            return View();
        }

        public ActionResult About()
        {
            return View();
        }
    }
}
